﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Wedo.Recognition.Domain.Models;

namespace Wedo.Domain.Models
{
    /// <summary>
    /// 用户
    /// </summary>
    [Table("C_UserInfo")]
    public partial class UserInfo : Entity
    {
        /// <summary>
        /// 名称
        /// </summary>
        [DisplayName("ADAccount")]//, ResourceType = typeof(Wedo.Recognition.Resources.UserInfo))]
        [Required(ErrorMessage = "域账号不能为空")]
        public string Name { set; get; }

        /// <summary>
        /// 所在角色
        /// </summary>
        [DisplayName( "所在角色")]
        public virtual List<Role> Roles { get; set; }

        /// <summary>
        /// 密码
        /// </summary>
        [DisplayName( "密码")]
        public string Password { get; set; }
    }

    /// <summary>
    /// 角色
    /// </summary>
    [Table("C_Role")]
    public partial class Role 
    {
        /// <summary>
        /// 主键（可以为字符串不能为空）
        /// </summary>
        [Key]
        public string Id { get; set; }

        /// <summary>
        /// 角色名称
        /// </summary>
        [DisplayName("RoleName")]//, ResourceType = typeof(Wedo.Recognition.Resources.Role))]
        [Required(ErrorMessage = "角色名不能为空")]
        public string RoleName { set; get; }

        [DisplayName("Description")]//, ResourceType = typeof(Wedo.Recognition.Resources.Role))]
        public string Description { set; get; }

        public virtual List<UserInfo> UserInfos { get; set; }

        public virtual List<Resource> Resources { get; set; }
    }
 

    /// <summary>
    /// 模块
    /// </summary>
    [Table("C_Module")]
    public partial class Module : Entity
    {
        /// <summary>
        /// 排序
        /// </summary>
        public int Order { set; get; }

        [StringLength(50)]
        [DisplayName( "名称")]
        public string Name { get; set; }

        [Display(Name="资源")]
        public virtual List<Resource> Resources { get; set; }
    }

    /// <summary>
    /// 资源
    /// </summary>
    [Table("C_Resource")]
    public class Resource : Entity
    {
        [DisplayName( "模块")]
        public Guid Module_Id { set; get; }

        /// <summary>
        /// 所在模块
        /// </summary>
       [ForeignKey("Module_Id")]
        public virtual Module Module { set; get; }

        /// <summary>
        /// 名称
        /// </summary>
        [DisplayName( "名称")]
        [Required]
        [StringLength(50)]
        public string Name { set; get; }

        /// <summary>
        /// 控制器的名称
        /// </summary> 
        [StringLength(50)]
        public string Controller { get; set; }

        /// <summary>
        /// Action名称
        /// </summary>
        [StringLength(50)]
        public string Action { get; set; }

        /// <summary>
        /// 是否为菜单
        /// </summary>
        [DisplayName( "是否为菜单")]
        public bool Navigator { set; get; }

        [DisplayName( "排序")]
        public int Order { get; set; }

        /// <summary>
        /// 关联的角色
        /// </summary>
        [DisplayName( "关联的角色")]
        public virtual List<Role> Roles { set; get; }


        public override bool Equals(object obj)
        {
            if (obj == null || !(obj is Resource))
                return false;
            return (obj as Resource).Id == Id;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

    }

    public class RoleUserInfoes
    {
        public Guid UserInfo_Id { get; set; }
        public string Role_Id { get; set; }
    }

    public class ResourceRoles
    {
        public Guid Resource_Id { get; set; }
        public string Role_Id { get; set; }
    }
  
}
